package com.dbms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dbms.domain.dto.BisModelPsparmsDTO;
import com.dbms.domain.entity.BisModelPsparms;
import com.dbms.domain.vo.BisModelPsparmsVO;
import com.dbms.mapper.BisModelPsparmsMapper;
import com.dbms.service.BisModelPsparmsService;
import com.dbms.utils.SnowflakeIdGenerator;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
public class BisModelPsparmsServiceImpl implements BisModelPsparmsService {

    final BisModelPsparmsMapper mapper;
    final SnowflakeIdGenerator snowflakeIdGenerator;

    @Override
    public boolean saveOrUpdate(BisModelPsparmsDTO dto) {
        if(StringUtils.isBlank(dto.getId())){
            BisModelPsparms psparms = new BisModelPsparms();
            BeanUtils.copyProperties(dto,psparms);
            psparms.setId(snowflakeIdGenerator.nextId().toString());
            mapper.insertSelective(psparms);
        }else{
            BisModelPsparms psparms = mapper.selectById(dto.getId());
            BeanUtils.copyProperties(dto,psparms);
            mapper.updateById(psparms);
        }
        return Boolean.TRUE;
    }

    @Override
    public BisModelPsparms queryInfo() {
        return mapper.selectOne(new LambdaQueryWrapper<BisModelPsparms>());
    }

    @Override
    public BisModelPsparmsVO queryInfo2() {
        BisModelPsparms psparms = mapper.selectOne(new LambdaQueryWrapper<BisModelPsparms>());
        BisModelPsparmsVO vo = new BisModelPsparmsVO();
        if(ObjectUtils.isNotEmpty(psparms)){
            BeanUtils.copyProperties(psparms,vo);
        }
        return vo;
    }

    @Override
    public boolean deleteById(List<String> ids) {
        mapper.deleteBatchIds(ids);
        return Boolean.TRUE;
    }
}
